package org.example.design.abstractFactory.proxy;

import org.example.design.abstractFactory.itf.ICacheAdapter;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @Classname JDKInvocationHandler
 * @Description TODO
 * @Date 2020/10/30 4:21 下午
 * @Created by xiangjd
 */
public class JDKInvocationHandler implements InvocationHandler {

    private ICacheAdapter iCacheAdapter;

    public JDKInvocationHandler(ICacheAdapter cacheAdapter) {
        this.iCacheAdapter = cacheAdapter;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        return ICacheAdapter.class.getMethod(method.getName(), ClassLoaderUtils.getClazzByArgs(args)).invoke(iCacheAdapter, args);

    }
}
